<template>
  <div>
    <div>
      <div
        style="
          display: flex;
          align-items: center;
          font-size: 16px;
          margin-bottom: 10px;
        "
      >
        <van-image
          width="30"
          height="30"
          src="https://zehao.oss-cn-beijing.aliyuncs.com/logo.jpg"
        />
        <span style="margin-left: 10px">TQozon官方认证</span>
      </div>
      <div style="color: blue; font-size: 16px; margin-bottom: 20px">
        官网：<a target="_blank" href="https://www.tqozon.com"
          >www.tqozon.com</a
        >
      </div>
    </div>
    <van-cell-group>
      <van-field
        v-model="form.username"
        required
        clearable
        label-width="60px"
        label="用户名"
        right-icon="friends-o"
        placeholder="请输入用户名"
        @click-right-icon="$toast('question')"
      />
      <van-field
        v-model="form.password"
        type="password"
        label-width="60px"
        label="密码"
        placeholder="请输入密码"
        required
      />
    </van-cell-group>
    <van-button
      @click="loginAcc"
      style="margin-top: 20px"
      type="primary"
      size="large"
      >登录</van-button
    >
  </div>
</template>

<script>
/* eslint-disable */
import {showNotify} from "vant";
const axios = require("axios");
import Cookies from "js-cookie";
import router from "@/router.js";
import {baseURL} from "@/constant.js";

export default {
  data() {
    return {
      form: {
        username: "",
        password: "",
      },
    };
  },

  props: {
    url: String,
  },
  methods: {
    async loginAcc() {
      console.log("loginAcc");
      const queryString = new URLSearchParams(this.form).toString();
      // 发送 POST 请求
      let retJson = await axios.post(`${baseURL}/login`, this.form);
      retJson = retJson["data"];
      if (retJson["code"] == 200) {
        showNotify({message: "登录成功", position: "top"});
        await Cookies.set("token", retJson["token"], {expires: 7}); // 设置过期时间为 7 天
        let active = retJson["activate"];

        console.log();
        await Cookies.set("active", active); // 设置过期时间为 7 天
        // console.log(Cookies.get("token"));
        setTimeout(() => {
          router.replace("/home");
        }, 500);
      } else {
        showNotify({message: retJson["msg"], position: "top"});
      }
    },
  },
};
</script>
